package com.edu.system.service.impl;

import com.edu.system.domain.TClassExt;
import java.util.List;
import java.util.Optional;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.edu.system.mapper.TTeacherExtMapper;
import com.edu.system.domain.TTeacherExt;
import com.edu.system.service.ITTeacherExtService;

/**
 * 教师(智慧校园)Service业务层处理
 * 
 * @author xxxx
 * @date 2024-02-01
 */
@Service
public class TTeacherExtServiceImpl implements ITTeacherExtService 
{
    @Autowired
    private TTeacherExtMapper tTeacherExtMapper;

    /**
     * 查询教师(智慧校园)
     * 
     * @param id 教师(智慧校园)主键
     * @return 教师(智慧校园)
     */
    @Override
    public TTeacherExt selectTTeacherExtById(Long id)
    {
        return tTeacherExtMapper.selectTTeacherExtById(id);
    }

    @Override
    public TTeacherExt selectByEid(String eid) {
        return null;
    }

    /**
     * 查询教师(智慧校园)列表
     * 
     * @param tTeacherExt 教师(智慧校园)
     * @return 教师(智慧校园)
     */
    @Override
    public List<TTeacherExt> selectTTeacherExtList(TTeacherExt tTeacherExt)
    {
        return tTeacherExtMapper.selectTTeacherExtList(tTeacherExt);
    }

    @Override
    public TTeacherExt checkAndSaveByCode(TTeacherExt teacherExt) {
        List<TTeacherExt> tTeacherExts = tTeacherExtMapper.selectTTeacherExtList(
            TTeacherExt.builder().eid(teacherExt.getEid()).build()
        );

        return Optional.ofNullable(tTeacherExts)
            .filter(CollectionUtils::isNotEmpty)
            .map(a -> a.get(0))
            .orElseGet(() -> {
                teacherExt.setId(null);
                this.insertTTeacherExt(teacherExt);
                return teacherExt;
            });
    }

    /**
     * 新增教师(智慧校园)
     * 
     * @param tTeacherExt 教师(智慧校园)
     * @return 结果
     */
    @Override
    public int insertTTeacherExt(TTeacherExt tTeacherExt)
    {
        return tTeacherExtMapper.insertTTeacherExt(tTeacherExt);
    }

    /**
     * 修改教师(智慧校园)
     * 
     * @param tTeacherExt 教师(智慧校园)
     * @return 结果
     */
    @Override
    public int updateTTeacherExt(TTeacherExt tTeacherExt)
    {
        return tTeacherExtMapper.updateTTeacherExt(tTeacherExt);
    }

    /**
     * 批量删除教师(智慧校园)
     * 
     * @param ids 需要删除的教师(智慧校园)主键
     * @return 结果
     */
    @Override
    public int deleteTTeacherExtByIds(Long[] ids)
    {
        return tTeacherExtMapper.deleteTTeacherExtByIds(ids);
    }

    /**
     * 删除教师(智慧校园)信息
     * 
     * @param id 教师(智慧校园)主键
     * @return 结果
     */
    @Override
    public int deleteTTeacherExtById(Long id)
    {
        return tTeacherExtMapper.deleteTTeacherExtById(id);
    }
}
